﻿<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>个人中心</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <!--responsive-->
    <link rel="shortcut icon" href="../Content/img/jridge.ico"/>
    <link rel="bookmark" href="../Content/img/jridge.ico"/>
    <script src="../Scripts/jquery-1.10.2.min.js"></script>
    <script src="../Scripts/clipboard-polyfill.js"></script>
    <!--vue-->
    <script src="../Scripts/vue-2.5.9/vue.min.js"></script>
    <!--axios-->
    <script src="../Scripts/vue-2.5.9/axios.min.js"></script>
    <!--elementUI-->
    <script src="../Scripts/elementUI-2.2.2/index.js"></script>
    <link rel="stylesheet" href="../Scripts/elementUI-2.2.2/theme-chalk/index.css">
    <!--custom-->
    <link rel="stylesheet" href="../Content/vue-common.css">
    <script src="../Scripts/service/vue-service.js" ></script>
    <style>
        .el-form-item{ margin-bottom: 22px!important }
        .title{ overflow: hidden }
        .title b{
            display: inline-block;
            float: left;
            width: 20px;
            border-top: 10px solid transparent;
            border-bottom: 10px solid transparent;
            border-left: 20px solid #333;
        }
        .title span{
            float: left;
            margin-top: -1px;
            margin-left: -10px;
        }
    </style>
</head>
<body >
    <div id="app">
        <header-bar :pagename="pagename" :userinfo="userinfo"></header-bar>
        <div id="container">
            <div>
                <div class="title">
                    <b></b>
                    <span>密码修改</span>
                </div>
                <div style="max-width:500px;margin:0 auto">
                    <el-form status-icon label-width="100px" :model="password" status-icon :rules="rules" ref="password" >
                        <el-form-item label="旧密码" prop="oldPwd">
                            <el-input type="password" v-model="password.oldPwd"></el-input>
                        </el-form-item>
                        <el-form-item label="新密码" prop="newPwd">
                            <el-input type="password" v-model="password.newPwd"></el-input>
                        </el-form-item>
                        <el-form-item label="确认新密码" prop="newPwdTwice">
                            <el-input type="password" v-model="password.newPwdTwice"></el-input>
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary" @click="save('password')">确认</el-button>
                        </el-form-item>
                    </el-form>
                </div>
            </div>
            
        </div>
    </div>
    <script>
            
            var vm = new Vue({
                el: '#app',
                data:function(){
                    var check_oldPwd = function(rule, value, callback){
                        var self = vm;
                        var param = {
                            "userName":self.userinfo.user.properties.staffno,
                            "password":value,
                            "property" :'staffno'
                        }
                        self.common_fn.invokeFun('Login',param,self.userinfo,function(response){
                            if(response.resFlag != 0){
                                callback(new Error('旧密码不正确，请重新输入'))
                            }else{
                                callback()
                            }
                        })
                    }
                    var check_newPwd = function(rule, value, callback){
                        if(vm.password.newPwdTwice != value){
                            callback(new Error('两次密码输入不一致，请重新输入'))
                        }else{
                            callback()
                        }
                    }
                    var check_newPwdTwice = function(rule, value, callback){
                        if(vm.password.newPwd != value){
                            callback(new Error('两次密码输入不一致，请重新输入'))
                        }else{
                            callback()
                        }
                    }
                    return{
                        pagename:"个人中心",
                        common_fn:null,
                        userinfo:null,
                        password:{
                            oldPwd:'',
                            newPwd:'',
                            newPwdTwice:'',
                        },
                        rules: {
                            oldPwd: [
                                { validator: check_oldPwd, trigger: 'blur' }
                            ],
                            newPwd: [
                                { validator: check_newPwd, trigger: 'blur' }
                            ],
                            newPwdTwice: [
                                { validator: check_newPwdTwice, trigger: 'blur' }
                            ]
                        },
                    }
                },
                methods:{
                    //保存
                    save:function(password){
                        var self = this;
                        this.$refs[password].validate(function(valid){
                            if (valid) {
                                var param = {
                                    "newGraph":{
                                        "roots": [{
                                            "entity": {
                                                "id": self.userinfo.user.id,
                                                "type": 'SysPerson',
                                                "properties": {
                                                    "password":self.newPwdTwice
                                                }
                                            },
                                            "nodeId": 0,
                                            "children": [],
                                            "strategy": 130
                                        }]
                                    }
                                }
                                self.common_fn.invokeFun('BatchDo',param,self.userinfo,function(response){
                                    if(response.resFlag == 0){
                                        notify_timeOut('密码修改成功，即将重新登陆','success');
                                        window.setTimeout(function(){
                                            window.location.href = 'login.html?redirect=personcenter.html';
                                        },3000)
                                    }else{
                                        notify(response.errMsg,'error');
                                    }
                                })
                            } else {
                                return false;
                            }
                        });
                        
                    }
                },
                mounted:function(){
                    var self = this;
                    self.common_fn = new common_fn();
                    self.common_fn.init(function(){
                        self.common_fn.UserInfo(function(response){
                            if(response.user == null){
                                window.location.href = 'login.html?redirect=personcenter.html';
                            }
                            self.userinfo = response;
                        })
                    });
                }
            })
        </script>
    <script src="../Template/vue-components.js" ></script>
    
</body>
</html>
